<template>
    <div class="login-container">
      <div class="login_title">
        <div class="logo"></div>
        <div class="logo_title"></div>
      </div>
    <el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left" label-width="0px"
      class="card-box login-form">
      <div class="enter_item">
        <label>用户名</label>
        <el-form-item prop="username">
          <el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" />
        </el-form-item>
      </div>
      <div class="enter_item">
        <label>密码</label>
        <el-form-item prop="password">
          <el-input name="password" type="password" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="off"
                   ></el-input>
        </el-form-item>
      </div>
     <!-- <div class="enter_item enter_checkbox">
        <template>
          <el-radio-group>
            <el-checkbox label="记住密码"></el-checkbox>
          </el-radio-group>
        </template>
      </div>-->
      <div class="enter_item enter_btn">
        <el-form-item>
          <el-button type="primary" :loading="loading" @click.native.prevent="handleLogin">
            登录
          </el-button>
        </el-form-item>
      </div>

    </el-form>
  </div>
</template>

<script>
import { isvalidUsername } from '@/utils/validate'
import req from '@/utils/req'
import * as User from "../../api/system";
export default {
  name: 'login',

  data() {
    const validateUsername = (rule, value, callback) => {
      if (!isvalidUsername(value)) {
        callback(new Error('请输入正确的用户名'))
      } else {
        callback()
      }
    }
    const validatePass = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('密码不能小于6位'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePass }]
      },
      loading: false
    }
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true


          this.$store.dispatch('Login', this.loginForm).then(() => {
            var router = this.$router.options.routes;//处理权限
            this.loading = false;
            this.$router.push({ path: '/'})
            /*/!*req.get("/homepage/findbyid").then(data=>{
              console.log(data.obj);
               if(data!=null&&data!=''){
                this.$router.push({ path: ''+data.message})
               }
            })*!/*/

          }).catch((e) => {

            this.loading = false
          })
        } else {

          return false
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
  @import "src/styles/mixin.scss";
  $bg:#2d3a4b;
  $dark_gray:#889aa4;
  $light_gray:#eee;

  .login-container {
    position:relative;
    width:100%;
    height: 100vh;
    background:url("../../assets/dw_icon/login_bg.png") no-repeat 0 0;
    background-size:contain;
    input {
      background: #fff;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 10px 5px 10px 15px;
      height: 36px;
      width:100%;
      border: 1px solid #ccc;
      background: #fff;
      border-radius: 5px;
      color: #666;
    }
    .el-input {
      display: inline-block;
      height: 36px;
      width: 100%;
      background: #fff;
    }
    .tips {
      font-size: 14px;
      color: #fff;
      margin-bottom: 10px;
    }
    .svg-container {
      padding: 6px 5px 6px 15px;
      color: #666;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .icon_enterlogo{
      display: inline-block;
      width:370px;
      height:35px;
      background:url("../../assets/icon/icon_enterlogo.png") no-repeat 0 0 ;
      margin: 0 0 40px 0px;
    }
    .login-form {
      position: absolute;
      left: 0;
      right: 0;
      top: 45%;
      width:450px;
      padding: 35px 35px 15px 35px;
      margin: 0px auto;
    }
    .el-form-item {
      float:right;
      width:320px;
    }
    .enter_item label{
      float:left;
      width:60px;
      height:36px;
      line-height: 36px;
    }
    .enter_item{
      display: inline-block;
      content:'';
      clear: both;
      width:380px;
      height:36px;
      margin-bottom: 20px;
    }
    .enter_item.enter_checkbox{
      margin-left: 60px;
    }
    .enter_item.enter_checkbox .el-checkbox__inner{
      margin-top: -10px;
    }
    .enter_btn .el-button{
      height:36px;
      width:100%;
    }
    .login_title {
      margin: 0 auto;
      width: 609px;
      height: 300px;
      padding: 100px;
    }
    .logo {
      width: 360px;
      height: 100px;
      background:url("../../assets/dw_icon/logo.png") no-repeat 0 0;
      margin-bottom: 50px;
    }
    .logo_title {
      width: 610px;
      height: 100px;
      background:url("../../assets/dw_icon/login_title.png") no-repeat 0 0;
      margin-left: -100px;
    }

  }

</style>
